﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ParsecClient
{
    /// <summary>
    /// Interaction logic for PasswordWindow.xaml
    /// </summary>
    public partial class PasswordWindow : Window
    {
        public PasswordWindow()
        {
            InitializeComponent();
        }
        public PasswordWindow(string message, EventHandler<PasswordOkEventArgs> okEventHandler, EventHandler<RoutedEventArgs> cancelEventHandler)
        {
            InitializeComponent();
            txtContent.Text = message;
            if (okEventHandler != null)
                Ok += okEventHandler;
            if (cancelEventHandler != null)
                Cancel += cancelEventHandler;
        }

        public event EventHandler<PasswordOkEventArgs> Ok;
        public event EventHandler<RoutedEventArgs> Cancel;
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            EventHandler<PasswordOkEventArgs> handler = Ok;
            if (handler != null)
            {
                handler(this, new PasswordOkEventArgs() { Password = txtPassword.Text });
            }
            else
            {
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            EventHandler<RoutedEventArgs> handler = Cancel;
            if (handler != null)
            {
                handler(this, e);
            }
            else
            {
                this.Close();
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            txtPassword.Focus();
        }

        private void txtPassword_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Return)
            {
                btnOk_Click(btnOk, e);
            }
        }
    }
    public class PasswordOkEventArgs : RoutedEventArgs
    {
        public string Password { get; set; }
    }
}
